package com.yjhb.android.sbz.mvp.checklist;

import com.yjhb.android.sbz.entity.BatchCheck;
import com.yjhb.android.sbz.entity.CheckResult;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/12/15 15:43
 */
public class CheckListPresenter extends ConventionPresenter<CheckListView> {
    private final String TAG = "CheckListPresenter";

    public CheckListPresenter(CheckListView checkListView) {
        super(checkListView);
    }

    @Override
    protected void onDestroy() {

    }

    public void getCheckList(String task, Integer state, Integer size, final Integer current) {
        HttpTool.request(model.auditList(task, state, size, current), new HttpObserver<List<CheckResult>>() {
            @Override
            public void onResult(List<CheckResult> data) {
                if (view != null) {
                    if (current == 1) {
                        view.onRefresh(data);
                    } else {
                        view.onLoad(data);
                    }
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

    public void batchConfirm(BatchCheck batchCheck) {
        if (view != null) {
            view.onWait("处理中，请稍候..");
        }
        HttpTool.request(model.batchConfirm(batchCheck), new HttpObserver<Integer>() {
            @Override
            public void onResult(Integer data) {
                if (view != null) {
                    view.onBatchCheckSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
